
function myNew(constructor,...args) {

    const obj = Object.create(constructor.prototype);
    const result = constructor.apply(obj,args);

    if(result && (typeof result == 'object' || typeof result == 'function')) {
        return result;
    }

    return obj;
}

function Person(name,age,sex) {

    this.name = name;
    this.age = age;
    this.sex = sex;

    return true;
}
Person.prototype.sayHi = function() {
    console.log(`hi`)
}

const p1 = new Person('daxia',20,'man');
const p2 = myNew(Person,'xiamin',18,'man');

console.log(p1);
console.log(p2);